package com.axend.aerosense.dev.adapter;

import com.axend.aerosense.common.adapter.BaseBindingAdapter;
import com.axend.aerosense.common.bean.RadarType;
import com.axend.aerosense.common.connect.bean.BleScanResultBean;
import com.axend.aerosense.dev.R;
import com.axend.aerosense.dev.databinding.DevLayoutChooseDeviceItemBinding;

public class DevScanDeviceAdapter extends BaseBindingAdapter<BleScanResultBean, DevLayoutChooseDeviceItemBinding> {

    private OnItemClickListener onItemClickListener;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.dev_layout_choose_device_item;
    }

    @Override
    protected void onBindItem(DevLayoutChooseDeviceItemBinding binding,
                              BleScanResultBean item,
                              int position) {

        binding.devName.setText(item.getRadarType().getName());
        binding.devImage.setImageResource(item.getRadarType().getImageRes());

        binding.devItemConstraintLayout.setOnClickListener(v -> {
            if (onItemClickListener != null)
                onItemClickListener.onClick(item.getRadarType());
        });
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onClick(RadarType deviceType);
    }
}
